package com.znsd.zl.utils.reflect;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName ReflectUtil
 * @Description TODO
 * @Author zhubin
 * @Date 2020/8/17 10:18
 * @Version v1.0
 */
public class ReflectUtil {
	/**
	 *  解决父类加载不到属性问题
	 * @param result  反射对象
	 * @return  返回所有属性
	 */
	public static Field[] allField(Object result) {
		List<Field> fieldList = new ArrayList<>();
		Class clazz = result.getClass();
		while (clazz != null) {
			fieldList.addAll(Arrays.asList(clazz.getDeclaredFields()));
			// 获取父类字段
			clazz = clazz.getSuperclass();
		}
		// 将集合转换成数据
		Field[] fields = new Field[fieldList.size()];
		fieldList.toArray(fields);
		return fields;
	}
}
